/**
 * @Date 2023-02-09 17:14:09
 * @Remark
 */

// config
// state
import { makeAutoObservable, toJS } from "mobx";
// controller
// lib
import _ from "lodash";
// script & methods & public
import { PAGE_DEFAULT } from "config/setting";
// 其它

export interface SearchValue {
  roleName?: string;
}

// function createList(codeMap?: any): StrOptionList {
//   const result: StrOptionList = [];
//   if (codeMap && !_.isEmpty(codeMap)) {
//     console.log("codeMap", codeMap);
//     for (const key in codeMap) {
//       console.log("key", key);
//       console.log("keykey", codeMap[key]);
//       result.push({
//         code: codeMap[key].id,
//         name: codeMap[key].id,
//       });
//     }
//   }
//   return result;
// }

class State {
  loading = false;
  disable = false;
  list: BookDto[] = [];
  treeList: CategoryDto[] = [];
  roomList:RoomDto[] = [];
  categoryList:CategoryDto[] = []
  // proAttrGroupLongList: any[] = [];
  total = 0;
  page = PAGE_DEFAULT.BEGIN;
  size = PAGE_DEFAULT.SIZE;
  search: SearchValue = {};
  editModal: BookDto | boolean = false;
  editModalLoading = false;
  // SpecificationEnum: any = [];
  constructor() {
    makeAutoObservable(this);
  }
  setSearch(val: SearchValue = {}) {
    this.search = val;
  }
  getSearch() {
    return toJS(this.search);
  }
  getList() {
    return toJS(this.list);
  }
  getTreeList() {
    return toJS(this.treeList);
  }
  getRoomList(){
    return toJS(this.roomList)
  }
  getCategoryList(){
    return toJS(this.categoryList)
  }
  setPage(val = PAGE_DEFAULT.BEGIN) {
    this.page = val;
  }
  setSize(val = PAGE_DEFAULT.SIZE) {
    this.size = val;
  }
  get editModalShow() {
    return !!this.editModal;
  }
  get editInfo() {
    if (typeof this.editModal !== "boolean") {
      return toJS(this.editModal);
    }
    return null;
  }

}

export const state = new State();
